package com.tansty.web.config.security;


import com.tansty.common.utils.MD5Util;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * description:  <br>
 * date: 2021/8/1 18:22 <br>
 * author: ztz <br>
 * version: 1.0 <br>
 * @author Tansty
 */
@Component
public class MyPasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(CharSequence rawPassword) {
        return MD5Util.encode((String) rawPassword) ;
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodePassword) {
        // 这边会对数据库中的密码也进行一次MD5加密，所以需要对原来的密码进行两次加密才能认证成功
        return  (MD5Util.encode( (String) rawPassword)).equals(encodePassword);
    }

}
